﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.BLL;
using WebApplication1.Models;

namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        UserInfoBLL userbll = new UserInfoBLL();
        SchoolBLL schbll = new SchoolBLL();
        GrowBLL growbll = new GrowBLL();

        public ActionResult Index()
        {
            return View();
        }

        //public string GetHello()
        //{
        //    String callbackFunName = Request["jsoncallback"];
        //    string back = callbackFunName + "({msg:'你好，服务地址可用了'})";
        //    return back;
        //}

        /// <summary>
        /// 验证登录
        /// </summary>
        /// <returns></returns>
        public string GetLogin()
        {
            string backTxt = "";
            string userId = "";//登录成功后获取到的用户id
            int check = 0;
            try
            {
                string user = Request["user"];
                string pwd = Request["pwd"];
                if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pwd))
                {
                    return "0";
                }
                DataTable dt = userbll.GetUser(user, pwd, out check, out userId);
                if (check == 1)
                {    //登录成功
                    backTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
                    backTxt = backTxt.TrimStart('[').TrimEnd(']');//去掉一行记录的前后中括号
                    //记录登录日志
                    userbll.AddLoginLog(userId);
                }
                backTxt = string.IsNullOrEmpty(backTxt) == true ? "null" : backTxt;
                backTxt = "{\"check\":" + check + ",\"model\":" + backTxt + "}";
            }
            catch (Exception ex)
            {
                backTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + backTxt + ")";
            return back;
        }

        /// <summary>
        /// 查询学校简介
        /// </summary>
        /// <returns></returns>
        public string GetSchoolIntro()
        {
            string schoolId = Request["schoolId"];
            object dt = schbll.GetSchoolIntrodution(schoolId);
            string jsonTxt = "";
            if (dt != null)
            {
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
                jsonTxt = jsonTxt.TrimStart('[').TrimEnd(']');//去掉一行记录的前后中括号
            }
            jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 查询宝宝食谱,参数1表示本周，2表示上周，3表示下周
        /// </summary>
        /// <param name="week"></param>
        /// <returns></returns>
        public string GetRecipeList(int week)
        {
            string schoolId = Request["schoolId"];
            string date = "";//  
            if (week == 1)//本周
            {
                date = DateTime.Now.ToString("yyyy-MM-dd");
            }
            else if (week == 2)//上一周
            {
                date = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
            }
            else if (week == 3)//下一周
            {
                date = DateTime.Now.AddDays(7).ToString("yyyy-MM-dd");
            }
            string[] arr = GetDateOfWeek(date);
            string week1 = arr[0];//本周星期一日期
            string week5 = arr[1];//本周星期五日期
            List<DateWeekTxt> weeklist = schbll.GetRicepe(schoolId, week1, week5);
            string jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(weeklist);
            jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 查询宝宝课程,参数1表示本周，2表示上周，3表示下周
        /// </summary>
        /// <param name="week"></param>
        /// <returns></returns>
        public string GetCourseList(int week)
        {
            string schoolId = Request["schoolId"];
            string date = "";//  
            if (week == 1)//本周
            {
                date = DateTime.Now.ToString("yyyy-MM-dd");
            }
            else if (week == 2)//上一周
            {
                date = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
            }
            else if (week == 3)//下一周
            {
                date = DateTime.Now.AddDays(7).ToString("yyyy-MM-dd");
            }
            string[] arr = GetDateOfWeek(date);
            string week1 = arr[0];//本周星期一日期
            string week5 = arr[1];//本周星期五日期
            List<DateWeekTxt> weeklist = schbll.GetCourseList(schoolId, week1, week5);
            string jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(weeklist);
            jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 根据任一日期返回它当周的星期一、星期五日期，下标0是周一，下标1为周五
        /// </summary>
        /// <param name="date">任一日期字符串</param>
        /// <returns></returns>
        public string[] GetDateOfWeek(string date)
        {
            DateTime date99 = Convert.ToDateTime(date);
            var kkmm = (int)date99.DayOfWeek;
            if (kkmm == 0)
            {
                kkmm = 6;
            }
            else
            {
                kkmm = kkmm - 1;
            }
            string week1 = date99.AddDays(-1 * kkmm).ToString("yyyy-MM-dd");//本周星期一日期
            string week5 = date99.AddDays(5 - kkmm - 1).ToString("yyyy-MM-dd");//本周星期五日期
            string[] arr = new string[2];
            arr[0] = week1;
            arr[1] = week5;
            return arr;
        }

        /// <summary>
        /// 获取新闻列表
        /// </summary>
        /// <returns></returns>
        public string GetNewsList()
        {
            string jsonTxt = "";
            try
            {
                int pageIndex = 1;
                int pageSize = 3;
                if (Request["pageIndex"] != null && Request["pageIndex"] != "")
                {
                    pageIndex = Convert.ToInt32(Request["pageIndex"]);
                }
                if (Request["pageSize"] != null && Request["pageSize"] != "")
                {
                    pageSize = Convert.ToInt32(Request["pageSize"]);
                }
                string userId = Request["userId"];//用户id
                //查询当前幼儿园的新闻
                JiaZhang jiazmodel = userbll.GetJiaZhang(userId);
                if (jiazmodel != null)
                {
                    object dt = schbll.GetNews(pageIndex, pageSize, userId, jiazmodel.schoolId);
                    jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
                    jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
                }
                else
                {
                    jsonTxt = "null";
                }
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 根据主键查询详细
        /// </summary>
        /// <returns></returns>
        public string GetNewsById(string id, string teacherServerAddress)
        {
            object dt = schbll.GetNewsById(id, teacherServerAddress);
            string jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
            jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt.TrimStart('[').TrimEnd(']');
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 获取通知活动列表
        /// </summary>
        /// <returns></returns>
        public string GetActiveList()
        {
            string jsonTxt = "";
            try
            {
                int pageIndex = 1;
                int pageSize = 3;
                if (Request["pageIndex"] != null && Request["pageIndex"] != "")
                {
                    pageIndex = Convert.ToInt32(Request["pageIndex"]);
                }
                if (Request["pageSize"] != null && Request["pageSize"] != "")
                {
                    pageSize = Convert.ToInt32(Request["pageSize"]);
                }
                string schoolId = Request["schoolId"];
                string userId = Request["userId"];
                object dt = schbll.GetActiveList(pageIndex, pageSize, schoolId, userId);
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
                jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 根据通知活动主键查询详细
        /// </summary>
        /// <returns></returns>
        public string GetActivityById(string id, string bsServerAddress)
        {
            object dt = schbll.GetActivityId(id, bsServerAddress);
            string jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
            jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt.TrimStart('[').TrimEnd(']');
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 根据学校id和家长用户id查询有权限的视频列表
        /// </summary>
        /// <returns></returns>
        public string GetVideoList()
        {
            string schoolId = Request["schoolId"];
            string userId = Request["userId"];
            object dt = schbll.GetVideoList(schoolId, userId);
            string jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
            jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 保存互动留言发送的消息
        /// </summary>
        /// <returns></returns>
        [ValidateInput(false)]
        public ActionResult SendMsg(string words, string schoolId, string receivePersonId, string sendPersonId)
        {
            int count = 0;
            JiaoLiu model = null;
            string jsonTxt = "";
            try
            {
                count = schbll.AddMsg(receivePersonId, sendPersonId, words, schoolId, out model);
            }
            catch (Exception ex)
            {
                string saveFolder = "Log\\Controller";
                string msg = "Home/SendMsg，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
                count = 0;
            }
            if (model != null)
            {
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(model);
            }
            jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "({\"success\":" + count + ",\"model\":" + jsonTxt + "})";
            return Content(back);
        }

        /// <summary>
        /// 获取互动留言联系人列表
        /// </summary>
        /// <returns></returns>
        public string GetContactList()
        {
            string jsonTxt = "";
            try
            {
                string classId = Request["classId"];//用户所在班级
                object dt = schbll.GetContractList(classId);
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
                jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            }
            catch (Exception ex)
            {
                jsonTxt = "\"error500\"";
                string saveFolder = "Log\\Controller";
                string msg = "Home/GetContactList，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        //获取每个教师的消息状态，未读消息个数，回复时间
        public string GetMsgInfo()
        {
            string jsonTxt = "";
            try
            {
                string teacherId = Request["teacherId"];//用户所在班级
                string userId = Request["userId"];//用户所在班级
                object info = schbll.GetMsgInfo(teacherId, userId);
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(info);
            }
            catch (Exception ex)
            {
                jsonTxt = "\"error500\"";
                string saveFolder = "Log\\Controller";
                string msg = "Home/GetMsgInfo，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 获取消息记录
        /// </summary>
        /// <returns></returns>
        public string GetMsgList()
        {
            string jsonTxt = "";
            try
            {
                int pageindex = 1;//页码
                if (!string.IsNullOrEmpty(Request["pageindex"]))
                {
                    pageindex = Convert.ToInt32(Request["pageindex"]);
                }
                string teacherId = Request["teacherId"];//教师id
                //string studentId = Request["studentId"];//学生id
                string userId = Request["userId"];//用户id
                string serverAddress = Request["serverAddress"];//服务器地址
                int msgCount = 5;
                if (string.IsNullOrEmpty(Request["msgCount"]) == false)
                {
                    msgCount = Convert.ToInt32(Request["msgCount"]);//未读的消息个数   
                }
                object list = schbll.GetMsgList(pageindex, 4, teacherId, userId, serverAddress);
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(list);
                jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            }
            catch (Exception ex)
            {
                jsonTxt = "\"error500\"";
                string saveFolder = "Log\\Controller";
                string msg = "Home/GetMsgList，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 修改消息状态
        /// </summary>
        /// <returns></returns>
        public string UpdateReadState()
        {
            string userId = Request["userId"];
            string teachId = Request["teachId"];
            string readyState = Request["readyState"];
            int efCount = 0; try
            {
                int count = schbll.UpdateReadState(userId, teachId, readyState);
                if (count > 0)
                {
                    efCount = 1;
                }
                else
                {
                    efCount = 0;
                }
            }
            catch (Exception)
            {
                efCount = 0;
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "({'success':" + efCount + "})";
            return back;
        }

        /// <summary>
        /// 获取签到日历
        /// </summary>
        /// <returns></returns>
        public string GetQianDaoRiLi()
        {
            string jsonTxt = "";
            try
            {
                string studentId = Request["studentId"];
                string schoolId = Request["schoolId"];
                string selectMonth = "";
                if (string.IsNullOrEmpty(Request["selectMonth"]) == false)
                {
                    selectMonth = Request["selectMonth"].Replace("年", "-");//格式“2015-12”
                    selectMonth = selectMonth.TrimEnd('月');
                }
                object obj = schbll.GetQianDaoRiLi(schoolId, studentId, selectMonth);
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
                jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 获取学生某天的签到记录
        /// </summary>
        /// <returns></returns>
        public string GetQiandaoByDay()
        {
            string jsonTxt = "";
            try
            {
                string studentId = Request["studentId"];
                string date = Request["date"];
                object dt = schbll.GetQiandaoByDay(studentId, date);
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
                jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 获取app更新版本
        /// </summary>
        /// <returns></returns>
        public string GetUpdatApp()
        {
            string jsonTxt = "";
            try
            {
                object dt = userbll.GetAppNewest();
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
                jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt.TrimStart('[').TrimEnd(']');
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 根据主键获取学生id
        /// </summary>
        /// <returns></returns>
        public string GetStudentById()
        {
            string jsonTxt = "";
            try
            {
                string stuid = Request["stuId"];//发送者id
                Student model = schbll.GetStudent(stuid);
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(model);
                jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt.TrimStart('[').TrimEnd(']');
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 修改通知活动阅读状态
        /// </summary>
        /// <returns></returns>
        public string UpdateNoticeActivityReadStatus()
        {
            string jsonTxt = "";
            try
            {
                string userid = Request["userid"];//用户id
                string wzid = Request["wzid"];//文章id                
                int count = schbll.AddReadedNoticeActivity(userid, wzid);
                jsonTxt = count + "";
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 修改新闻阅读状态
        /// </summary>
        /// <returns></returns>
        public string UpdateNewsReadStatus()
        {
            string jsonTxt = "";
            try
            {
                string userid = Request["userid"];//用户id
                string wzid = Request["wzid"];//文章id
                int count = schbll.AddNewsReaded(userid, wzid);
                jsonTxt = count + "";
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 统计当前用户没有阅读的新闻、通知个数
        /// </summary>
        /// <returns></returns>
        public string GetNoReadCount()
        {
            string jsonTxt = "";
            try
            {
                string userId = Request["userId"];
                string schoolId = Request["schoolId"];
                object arr = schbll.GetNoReadCount(userId, schoolId);
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(arr);
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 上传成长档案发表的图片
        /// </summary>
        /// <returns></returns>
        public ActionResult UploadChengZhangDangAnImg()
        {
            try
            {
                HttpFileCollectionBase fileBase = this.HttpContext.Request.Files;
                HttpPostedFileBase file = fileBase.Get(0);
                int size = file.ContentLength;
                if (size > 8388608)
                {
                    return Content("Max8MB");
                }
                string name = file.FileName;
                string type = file.ContentType;
                string serverPath = Server.MapPath("~");

                string saveFolder = "Upload\\ChengZhangDangAn";
                string savePath = serverPath + saveFolder;
                if (!Directory.Exists(savePath))
                {
                    Directory.CreateDirectory(savePath);
                }
                //string fileNameQianZhui = Path.GetFileNameWithoutExtension(name);//文件名
                string fileNameHouZui = Path.GetExtension(name);//文件后缀名
                //检测文件真实类型
                if (string.IsNullOrEmpty(fileNameHouZui))
                {
                    byte[] fileTmpBytes = new byte[file.ContentLength];
                    file.InputStream.Read(fileTmpBytes, 0, file.ContentLength);
                    MemoryStream fileStream = new MemoryStream(fileTmpBytes);
                    string filetype = WebApplication1.Common.FileCommon.GetFileRealType(fileStream);//文件格式名
                    fileStream.Close();
                    fileStream.Dispose();
                    fileNameHouZui = "." + filetype;
                }
                string time = DateTime.Now.ToString("yyyy-MM-dd_HH_mm_ss_fff");
                string fileName = savePath + "\\" + time + "_Y" + fileNameHouZui;
                file.SaveAs(fileName);
                string newFilePath = savePath + "\\" + time + fileNameHouZui;
                Common.ImgChuLi.SendSmallImage(fileName, newFilePath, 1360, 1814, 80, "W");//指定宽，高按比例
                //删除原上传图片
                System.IO.File.Delete(fileName);
                //组装返回数据
                string fileNameSave = "/Upload/ChengZhangDangAn/" + time + fileNameHouZui;//保存到数据库的图片路径
                var fileJson = "{\"state\":\"success\",\"filePath\":\"" + fileNameSave + "\"}";
                return Content(fileJson);
            }
            catch (Exception)
            {
                return Content("error500");
            }
        }

        /// <summary>
        /// 保存成长档案说说和图片
        /// </summary>
        /// <returns></returns>
        public string SaveGrow(string imgList, string userId, string word, string schoolId, string classId)
        {
            string jsonTxt = "";
            try
            {
                string serverPath = this.HttpContext.Server.MapPath("~");//服务器路径
                if (!string.IsNullOrEmpty(word))
                {
                    if (word.Length > 140)
                    {
                        jsonTxt = "\"errorMaxLen140\"";
                        string back2 = Request["jsoncallback"] + "(" + jsonTxt + ")";
                        return back2;
                    }
                }
                int count1 = 0;
                if (string.IsNullOrEmpty(classId))
                {
                    count1 = growbll.AddGrowImgList(imgList, userId, word, schoolId, serverPath);//兼容以前版本
                }
                else
                {
                    count1 = growbll.AddGrowImgList2(imgList, userId, word, schoolId, classId, serverPath);//最新版本
                }
                jsonTxt = "\"1\"";
                string back = Request["jsoncallback"] + "(" + jsonTxt + ")";
                return back;
            }
            catch (Exception)
            {
                jsonTxt = "\"error500\"";
                string back = Request["jsoncallback"] + "(" + jsonTxt + ")";
                return back;
            }
        }

        /// <summary>
        /// 成长档案列表
        /// </summary>
        /// <returns></returns>
        public string GetGrowList(string classId, int pageIndex, int pageSize, string schoolId, string currentUserId, string serverAddress, string teacherServer)
        {
            string jsonTxt = "";
            try
            {
                object objlist = null;
                if (string.IsNullOrEmpty(teacherServer)==false)
                {
                    objlist = growbll.GetGrowList2(currentUserId, classId, pageIndex, pageSize, serverAddress, teacherServer);//最新版本
                }
                else
                {
                    objlist = growbll.GetGrowList(currentUserId, schoolId, pageIndex, pageSize, serverAddress);//兼容以前版本
                }
                jsonTxt = Newtonsoft.Json.JsonConvert.SerializeObject(objlist);
                jsonTxt = string.IsNullOrEmpty(jsonTxt) == true ? "null" : jsonTxt;
            }
            catch (Exception ex)
            {
                jsonTxt = "\"error500\"";
                string saveFolder = "Log\\Controller";
                string msg = "Home/GetGrowList，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 点赞
        /// </summary>
        /// <returns></returns>
        public string DianZan()
        {
            string jsonTxt = "";
            try
            {
                string userId = Request["userId"];//点赞的人id
                string zanGrowId = Request["zanGrowId"];//被赞的记录id     
                int count = growbll.AddZan(zanGrowId, userId);
                if (count == 1)
                {
                    jsonTxt = "\"1\"";
                }
            }
            catch (Exception ex)
            {
                jsonTxt = "\"error500\"";
                string saveFolder = "Log\\Controller";
                string msg = "Home/DianZan，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        /// <summary>
        /// 保存评论
        /// </summary>
        /// <returns></returns>
        public string AddPingLun()
        {
            string jsonTxt = "";
            try
            {
                string userId = Request["userId"];//评论人id
                string growId = Request["growId"];//被评论的记录id     
                string words = Request["words"];//评论
                if (string.IsNullOrEmpty(words) == false)
                {
                    int count = growbll.AddPingLun(userId, growId, words);
                    if (count == 1)
                    {
                        jsonTxt = "\"1\"";
                    }
                }
                else
                {
                    jsonTxt = "\"0\"";
                }
            }
            catch (Exception ex)
            {
                jsonTxt = "\"error500\"";
                string saveFolder = "Log\\Controller";
                string msg = "Home/AddPingLun，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        //获取未读的留言消息个数        
        public string GetMsgCount()
        {
            string jsonTxt = "";
            try
            {
                string userId = Request["userId"];
                int count = userbll.GetNoReadMsg(userId);
                jsonTxt = count + "";
            }
            catch (Exception ex)
            {
                jsonTxt = "\"error500\"";
                string saveFolder = "Log\\Controller";
                string msg = "Home/GetMsgCount，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        //反馈建议
        public string AddSuggest()
        {
            string jsonTxt = "";
            try
            {
                string userId = Request["userId"];
                string word = Request["word"];
                int count = userbll.AddSuggest(userId, word);
                jsonTxt = count + "";
            }
            catch (Exception ex)
            {
                jsonTxt = "\"error500\"";
                string saveFolder = "Log\\Controller";
                string msg = "Home/AddSuggest，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }

        //修改用户密码
        public string UpdateUserPwd()
        {
            string jsonTxt = "";
            try
            {
                string userId = Request["userId"];
                string password = Request["password"];
                string oldPwd = Request["oldPwd"];//原始密码
                //查询原始密码
                JiaZhang model = userbll.GetJiaZhang(userId);
                if (model != null)
                {
                    string jiami_pwd = Common.DESencodingTxt.DESencrypt(oldPwd);
                    if (jiami_pwd.Equals(model.password) == false)
                    {
                        jsonTxt = "2";//原始密码错误
                    }
                    else
                    {
                        int count = userbll.UpdateJiaZhangPwd(userId, password);
                        if (count > 0)
                        {
                            jsonTxt = "1";//修改成功
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                jsonTxt = "\"error500\"";
                string saveFolder = "Log\\Controller";
                string msg = "Home/UpdateUserPwd，" + ex.Message;
                Common.LogManager.AddLog(msg, saveFolder);
            }
            String callbackFunName = Request["jsoncallback"];
            string back = callbackFunName + "(" + jsonTxt + ")";
            return back;
        }


    }
}